﻿#pragma once

#include <iostream>
#include <osg/Matrix>
#include <osgViewer/Viewer>

/*
* @brief 打印矩阵的位姿信息
*/
void printPositionAttitude(const osg::Matrix& mat);

/*
* @brief 从 NodeVisitor 获取 Viewer
*/
osgViewer::Viewer* getViewerFromNodeVisitor(osg::NodeVisitor* nv);

class ChangeWindow : public osgGA::GUIEventHandler
{

public:
	virtual bool handle(osgGA::Event* event, osg::Object* object, osg::NodeVisitor* nv)
	{
		if (!first)
		{
			// 将 NodeVisitor 转换为 EventVisitor
			osgViewer::Viewer* viewer = getViewerFromNodeVisitor(nv);
			if (viewer != nullptr)
			{

				osgViewer::Viewer::Windows ws;
				first = true;

				viewer->getWindows(ws);
				if (!ws.empty())
				{
					osgViewer::Viewer::Windows::iterator iter = ws.begin();
					for (; iter != ws.end(); iter++)
					{
						std::cout << "set window" << std::endl;
						// (*iter)->setWindowRectangle(320, 150, 1920, 1080);
						(*iter)->setWindowDecoration(false);
						(*iter)->useCursor(true);
						(*iter)->setCursor(osgViewer::GraphicsWindow::CrosshairCursor);
					}

					/* 
					* Note : 以下两个方法也能改变窗口大小，但务必在 run() 之前调用，或者确保window存在时调用，否则会报错。
					* 	viewer->apply(new osgViewer::SingleWindow(100, 100, 800, 600, 0));
					*	viewer->setUpViewInWindow(100, 100, 800, 600);
					*/
				}
			}
		}
		return false;
	}

private:
	bool first = false;
};